<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String zixitongId = request.getParameter("zixitongId");
	String flag = request.getParameter("flag");
 %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title>选择委托单位</title>
		<meta http-equiv="X-UA-Compatible" content="IE=7" />
		<%@ include file="../jslib/jquerylib.jsp" %>
	    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
        <link href="<%=request.getContextPath() %>/web/style/layout.css" type="text/css" rel="stylesheet"/>
        <link rel="stylesheet" href="<%=request.getContextPath() %>/jslib/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
        <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/ztree/jquery.ztree.core-3.4.js"></script>
		<script type="text/javascript">
            var selectId = "" ;
            var actionUrl='';
            var colname = "零部件";
			if('<%=flag%>'=='0'){
				colname = "子系统";
			}
            $(document).ready(function(){
                $("#fromTable").jqGrid({
                  url:'<%=request.getContextPath() %>/weituodan!queryLingbujianAndZixitong.action?flag=<%=flag%>&zixitongId=<%=zixitongId%>',
                    datatype: "json",
                    height: 280,
                    autowidth: true, 
                    colNames:['序号',colname+'名称'],
					colModel:[
							{name:'ID',index:'ID', width:60, key:true, sorttype:"int",hidden:true,hidedlg:true}, 
							{name:'LINGBUJIANNAME',index:'LINGBUJIANNAME', width:100}
					],
                    shrinkToFit:false,
                    sortname:'ID',
                    sortorder:'desc',
                    viewrecords:true,
					multiselect: true, // 是否显示复选框
					gridview: true,  //提升速度
					rownumbers: true,
					rowNum:100,
					rowNum:<%=session.getAttribute("SYS_PAGECOUNT")%>,
					ondblClickRow: function(rowid){
			            var row = $("#fromTable").jqGrid('getRowData',rowid);
			            $("#fromTable").jqGrid('delRowData',rowid);
			            var result = "{'id':'"+row.ID+"','name':'"+row.LINGBUJIANNAME+"'}";
			       		
			       		if(row.ID==undefined&&row.WEITUODANWEI==undefined){
				       	}else{
				       		window.returnValue = result;
			       			window.close();	
				       	}
			        },
					rowList:[10,20,30,40,50],
					toolbar: [true,"top"],
					jsonReader: {
						root:"rows",		// 数据行（默认为：rows）
						page: "page",  	// 当前页
						total: "total",  // 总页数
						records: "records",  // 总记录数
						repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
					},
					prmNames:{rows:"rows",page:"page",sort:"ID",order:"sord",search:"search"},
					pager:"#fromPager",
					caption: colname+"列表"
                });
                 jQuery("#fromTable").jqGrid('navGrid','#fromPager',{add:false,edit:false,del:false,search:false,refresh:false});
                 
         //确定按钮
        $("#entry").click(function(){
	    	var rowid = $("#fromTable").getGridParam("selrow");
	    	var r = $("#fromTable").getGridParam("selarrrow")+"";
			if (!rowid) {   // (1)  
			    alert("请先选择记录!");  
			    return false;  
			} 
			if(r.indexOf(",")!=-1){
				  alert("只能选择一条记录!");  
			        return false; 
			 }
			var row = $("#fromTable").jqGrid('getRowData',rowid);
	    	var result = "{'id':'"+row.ID+"','name':'"+row.LINGBUJIANNAME+"'}";
	   	    window.returnValue = result;
	        window.close();
    });
       /**
	     * 取消
	     */
	    $("#center").click(function(){
	        window.close();
	    });
        });
       
	     
             //查询
            function gridSearch(){
                var shebeiname = $.trim($("#shebeiname").val());
                var shebeino = $.trim($("#shebeino").val());
			    var params = {
			        "shebeiname" : encodeURIComponent($.trim(shebeiname)),
			        "shebeino" : encodeURIComponent($.trim(shebeino))
			    };
			    var postData = $("#fromTable").jqGrid("getGridParam", "postData");
			    $.extend(postData, params);  //(9)将postData中的查询参数覆盖为空值
			    $("#fromTable").jqGrid('setGridParam',
			    {
			        url:'<%=request.getContextPath() %>/weituodan!queryLingbujianAndZixitong.action?flag=<%=flag%>&zixitongId=<%=zixitongId%>'
			    }).trigger("reloadGrid", [{page:1}]); 
            }     
            
            //清空按钮  
           function resetquery()
           {
             jQuery("#shebeiname").val('');
             jQuery("#shebeino").val('');
           }
           // 调用子集方式2	 
	 function callStateM2(json){
			 $("#bumen").empty();
				var html = '<option value="">--请选择--</option>';
				  $('#bumen').append(html);
				if(json!=''){
				$.each(json,function(entryindex,entry){
					html = '<option value="'+entry['id']+'">' + entry['zuzhi'] + '</option>';
					$('#bumen').append(html);
				});
			}
	}
    </script>

	</head>


	<body>
		<form action="" id="form1" method="post">
			<table  cellspacing="1" cellpadding="1"  width="100%">
				 <!--tr>
				     <td colspan="2">
						<table width="100%" border="0" cellspacing="0" cellpadding="0" class="font12Black_B">
							<tr>
								<td  align="center">设备名称：</td>
								<td  align="left"><input type="text" id="shebeiname" name="shebeiname" value="" class="search_InputText"/></td>
								<td  align="center">设备编号：</td>
								<td  align="left">
								    <input type="text" id="shebeino" name="shebeino" value="" class="search_InputText"/>
								</td>
								
							    <td align="left"> <input id="query" type="button" class="search_Btn" value="查 询"  onclick="gridSearch()" />&nbsp;&nbsp;
								<input type="button" class="search_Btn" value="清 空"  onclick="resetquery()" /></td>
							
							</tr>
						</table>
						 <div id="panel" style="display:none" >
				            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="font12Black_B">	
							</table>
							</div>
						</td>
				     </tr>
				 <tr>
			        <td colspan="2" align="right" height="9" class="sclinebotBg"></td>
			     </tr-->
			</table>

			<table style="width: 100%;" class="tableCont">
				<tr>
					<td colspan="4">
						<table id="fromTable"></table>
						<div id="fromPager"></div>
					</td>
				</tr>
			</table>
			<table style="width: 100%;">
			   <tr>
			   <td colspan="4" style="text-align: center; height: 20px; font-size: 15px; font-weight: bold;">
		        <button id="entry"  class="button_b">确&nbsp;定</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		        <button id="center" class="button_b" >取&nbsp;消</button>
		       </td>
		      </tr>
			</table>
		</form>
	</body>
</html>
